<?php
$functionListStr = Yii::t('BWeSport','Function list');
$functionSetUpStr = Yii::t('BWeSport','Function Set Up');
$functioninfoStr = Yii::t('BWeSport','Function Info');
$venderfullStr = Yii::t('BWeSport','Vender Full');
$saveStr = Yii::t('BWeSport','Save');
?>
<?php
$model = new BDynamicFormModel();
$modelClass = get_class($model);
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$url = $control->getAjaxLinkUrl('saveEvent', NULL, array(
    'eventId' => $eventId,
    'postModel' => $modelClass));
$updateId = $control->getAjaxContainerId();
?>

<?php
/*
  echo CHtml::beginForm(NULL, NULL, array(
  'id' => 'addEventForm',
  'enctype' => 'multipart/form-data'
  ));
 * 
 */
?>

<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addEventForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<link rel="stylesheet" type="text/css"
      href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datetimepicker.min.css" />
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datetimepicker.min.js"/>

<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function send<?php echo $eventId; ?>() {
        var eventType = $('#BDynamicFormModel_eventType_eventTypeId option:selected').val();
        var eventName = $('#BDynamicFormModel_event_name').val();
        var eventDescription = $('#BDynamicFormModel_event_description').val();
        var venderId = $('#BDynamicFormModel_media_venderId_vender').val();
        var venderName = $('#BDynamicFormModel_media_venderName_vender').val();
        var filepath=$('#BDynamicFormModel_image_media_image_vender').val(); 
        var extStart=filepath.lastIndexOf("."); 
        var ext=filepath.substring(extStart,filepath.length).toUpperCase(); 
     if(eventType != 0){
         if(eventName !=""){
             if(eventDescription !=""){
                 if(venderId !=""){
                     if(venderName !=""){
                         if(filepath !=""){
                             if(ext ==".BMP" || ext ==".PNG" || ext ==".GIF" || ext ==".JPG" || ext ==".JPEG"){
                                    var formData = new FormData($("#addEventForm")[0]);
                                    $.ajax({
                                        url: '<?php echo $url; ?>',
                                        type: 'POST',
                                        data: formData,
                                        //datatype: 'json',
                                        // async: false,
                                        beforeSend: function() {
                                            $("#ajax-loaderdiv").show();
                                        },
                                        success: function(html) {
                                            // on success do some validation or refresh the content div to display the uploaded images 
                                            jQuery("#<?php echo $updateId; ?>").html(html);
                                        },
                                        complete: function() {
                                            $("#ajax-loaderdiv").hide();
                                        },
                                        error: function(data) {
                                            alert("There may a error on uploading. Try again later");
                                        },
                                        cache: false,
                                        contentType: false,
                                        processData: false
                                    });
                              }else alert("图片限于bmp,png,gif,jpeg,jpg格式");
                         }else alert("请上传图片")
                     }else alert("请输入场地商名称");
                 }else alert("请输入场地商ID");
             }else alert("请输入功能简介");
         }else alert("请输入功能名称");
     }else alert("请选择功能类型");

        return false;
    }
</script>
<legend><h4><?php echo $control->getAjaxLink(array('name' => $functionListStr, 'id' => 'showEventList')); ?>\<?php echo $functionSetUpStr; ?>
    </h4></legend>
<div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
    <ul class="nav nav-tabs" style="margin-bottom: 15px">
        <li class="active"><a href="#tab1" data-toggle="tab"><?php echo $functioninfoStr; ?></a></li>          
        <li class=""><a href="#tab2" data-toggle="tab"><?php echo $venderfullStr; ?></a></li>            
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab1" style="min-height: 270px">                
            <?php
            $control->renderView('event_add_info', array(
                'eventId' => $eventId,
                'form' => $form,
                'model' => $model
            ));
            ?>  
        </div>     
        <div class="tab-pane" id="tab2" style="min-height: 270px">                
            <?php
            $control1 = new BUIControl('addVender');
            $control1->addRenderView('vender_add', 'vender_add', array(
                'eventId' => $eventId,
                'form' => $form,
                'model' => $model
            ));
            $control1->render();
            ?>  
        </div>
    </div>
</div>

<?php
/*
  $htmlOptions = array('class' => 'btn');
  if ($eventId == 0)
  $htmlOptions['disabled'] = 'disabled';
  echo $control->getAjaxLink(array('name' => 'Show bookable List', 'id' => 'showBookableList'), array(
  'eventId' => $eventId,
  'htmlOptions' => $htmlOptions));
 */
?>

<?php
$this->endWidget();
//echo CHtml::endForm();
?>
<button class="btn" onclick="javascript:send<?php echo $eventId; ?>()"><?php echo $saveStr ?></button>